﻿using SpiderMaster.Net.Exceptions;

namespace SpiderMaster.AspNet
{
    public sealed partial class TradingCenter
    {
        /// <summary> Only start after intialization of Applications.
        /// Each Application has sub proccess to initialize so once we have Intialized we can Thread safe use Start
        /// to activate each Application. These Applications will eventually have lock outs for 
        /// Registration and miss-use and more!!
        /// </summary>
        [ReganSchroder(4, 11, 19, 10, 2009)]
        public TradingCenter Start()
        {
            if (_Instance.IsNull())
                throw new InitializeInstanceException<TradingCenter>("Trading Center can not Start. Its Instance Does not exist in the Instance context.'");

            if (InvokePlugins && SystemProvider.Current.Count > 0)
                foreach (IPluginManagement manager in _Instance.GetAllPluginManagers())
                    manager.Load();

            _Instance.TaskScheduler.StartTasks();

            return _Instance;
        }
    }
}
